<?php
/**
 * @desc 控制器基类
 * @author kevin.wang
 * @date 2015-01-01 12:00:00
 */
class Controller extends CController
{
	//默认主题
	public $layout='//layouts/home';
	//json输出方法
	function renderJson($data){
		if(empty($data['msg'])){
			$errorCode = Yii::app()->params['errorCode'];
			$data['msg'] = $errorCode[$data['status']]['errorMsg'];
		}
        header("Content-type:json/application;charset=utf-8");
		$output = array(
			'header' => array(
					'version' => '1.0',
					'reqTime' => $_SERVER['REQUEST_TIME'],
					'repTime' => time(),
					'status' => $data['status'],
					'reqMsg' => $data['msg']
				),
			'body' => $data['body']
			);
        echo json_encode($output);
		Yii::app()->end();
    }
	//用户登录过滤
	function filterUserLogin($filterChain){
		$model = new LoginForm();
		$result = $model->userIsLogin();
		if(empty($result)){
			Yii::app()->session['rturnUrl'] = Yii::app()->request->url;
			$this->redirect(Yii::app()->createUrl("passport/login"));
		}
		$filterChain->run();
	}
}